<template>
  <div class="home">
      <ul>
          <li v-for="item in myCreateBolgs" :key="item.id">
              <h4>{{item.title}}</h4>
              <p>{{item.con}}</p>

              <button @click="edit(item.id)">修改</button>
              <button @click="del(item.id)">删除</button>
          </li>
      </ul>
  </div>
</template>

<script>
export default {
    data(){
        return {
            myCreateBolgs:[]
        }
    },
    created(){
        //请求数据
        this.getList();
    },
    methods:{
        getList(){
            this.$http.get('/api/list',{params:{author:localStorage.getItem('username')}}).then(res => {
                if(res.data.code === 1){
                    this.myCreateBolgs = res.data.data;
                }
            })  
        },
        del(id){
            this.$http.delete('/api/del',{params:{id}}).then(res => {
                if(res.data.code === 1){
                    alert("删除成功");
                    this.getList();
                }
            })
        },
        edit(id){
            this.$router.push({path:'/create_blog',query:{id}})
        }
    }
}
</script>